package com.maxsalad.pospal.job;

import com.maxsalad.eleme.service.OrderService;
import com.maxsalad.pospal.service.DishService;
import org.apache.commons.collections4.MapUtils;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;

/**
 * Created by 2014-400 on 2016-03-16.
 */
public class QueryDishJob implements Job {
    private static Logger log = LoggerFactory.getLogger(QueryDishJob.class);

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();

        ApplicationContext ctx = (ApplicationContext) jobDataMap.get("applicationContext");
        if (ctx != null) {
            DishService dishService = ctx.getBean("pospalDishService", DishService.class);
            if (dishService != null) {
                int size = MapUtils.getIntValue(jobDataMap, "size", 500);
                dishService.download(2);
            } else {
                log.error("com.maxsalad.pospal.job.QueryDishJob.execute:dishService对象为null");
            }
        } else {
            log.error("com.maxsalad.pospal.job.QueryDishJob.execute:ApplicationContext对象为null");
        }
    }
}
